<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="退费订单号" prop="id">
        <el-input v-model="queryParams.id" placeholder="退费订单号" clearable style="width: 240px;" size="mini"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="充值订单号" prop="topUpId">
        <el-input v-model="queryParams.topUpId" placeholder="充值订单号" clearable style="width: 240px;" size="mini"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="退费人" prop="memberRealName">
        <el-input v-model="queryParams.memberRealName" placeholder="退费人" clearable style="width: 240px;" size="mini"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="退费人手机号" prop="memberPhone">
        <el-input v-model="queryParams.memberPhone" placeholder="退费人手机号" clearable style="width: 240px;" size="mini"
                  @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="支付类型" prop="backType">
        <el-select v-model="queryParams.backType" placeholder="支付类型" clearable size="mini" style="width: 240px">
          <el-option v-for="dict in backTypeOptions" :key="dict.value" :label="dict.label" :value="+dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="退费类型" prop="type">
        <el-select v-model="queryParams.type" placeholder="支付类型" clearable size="mini" style="width: 240px">
          <el-option v-for="dict in typeOptions" :key="dict.value" :label="dict.label" :value="+dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="订单状态" clearable size="mini" style="width: 240px">
          <el-option v-for="dict in statusOptions" :key="dict.value" :label="dict.label" :value="+dict.value"/>
        </el-select>
      </el-form-item>
      <el-form-item label="创建时间">
        <el-date-picker v-model="dateRange" size="mini" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange" :height="tableHeight">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="退费订单号" width="200" align="center" prop="id"/>
      <el-table-column label="充值订单号" width="200" align="center" prop="topUpId"/>
      <el-table-column label="退费人" width="200" align="center" prop="memberRealName"/>
      <el-table-column label="退费人手机号" width="200" align="center" prop="memberPhone"/>
      <el-table-column label="退费时间" align="center" prop="backTime" width="140" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.backTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="平台交易号" align="center" prop="backPlatformId" width="200" :show-overflow-tooltip="true"/>
      <el-table-column label="退费金额" align="center" prop="amount">
        <template slot-scope="scope">
          <span>{{ scope.row.amount }} 元</span>
        </template>
      </el-table-column>
      <el-table-column label="交易类型" align="center" prop="backType">
        <template slot-scope="scope">
          <span v-if="scope.row.backType==0" style="color: red;font-weight: bolder">现金</span>
          <span v-if="scope.row.backType==1" style="color: #00afff;font-weight: bolder">支付宝</span>
          <span v-if="scope.row.backType==2" style="color: lawngreen;font-weight: bolder">微信</span>
        </template>
      </el-table-column>
      <el-table-column label="退费类型" align="center" prop="backType">
        <template slot-scope="scope">
          <span v-if="scope.row.type==0" style="color: red;font-weight: bolder">全额退款</span>
          <span v-if="scope.row.type==1" style="color: limegreen;font-weight: bolder">部分退款</span>
        </template>
      </el-table-column>
      <el-table-column label="订单状态" align="center" prop="status" :formatter="statusFormat"/>
      <el-table-column label="创建时间" align="center" prop="gmtCreate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.gmtCreate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.current" :limit.sync="queryParams.size"
                @pagination="getList"/>
  </div>
</template>

<script>

import { listRefund } from '@a/beauty/refund'

export default {
  name: 'refund',
  data() {
    return {
      tableHeight: window.innerHeight - 340,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      list: [],
      // 状态数据字典
      statusOptions: [],
      // 退费类型数据字典
      backTypeOptions: [],
      // 退费订单类型
      typeOptions: [],
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        id: undefined,
        topUpId: undefined,
        backType: undefined,
        type: undefined,
        status: undefined,
        memberRealName: undefined,
        memberPhone: undefined
      }
    }
  },
  created() {
    this.getList()
    this.getDictItems('beauty_refund_status').then(response => {
      this.statusOptions = response.data
    })
    this.getDictItems('beauty_refund_back_type').then(response => {
      this.backTypeOptions = response.data
    })
    this.getDictItems('beauty_refund_type').then(response => {
      this.typeOptions = response.data
    })
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      listRefund(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.list = response.data.records
          this.total = response.data.total
          this.loading = false
        }
      )
    },
    //状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status)
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.current = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.multiple = !selection.length
    }
  }
}
</script>

